package com.zqh.generator;

import java.io.*;

public class JarGenerator {

    public static void doGenerate(String projectDir) throws IOException, InterruptedException {

        String macMavenCommand = "/Users/zqh/apache-maven-3.9.9/bin/mvn clean package -DskipTests=true";
        String otherMavenCommand = "";

        String mavenCommand = macMavenCommand;

        ProcessBuilder processBuilder = new ProcessBuilder(mavenCommand.split(" "));
        processBuilder.directory(new File(projectDir));

        Process process = processBuilder.start();

        // 读取命令输出
        InputStream inputStream = process.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));

        String line;
        while ((line = reader.readLine()) != null){
            System.out.println(line);
        }

        // 等待执行命令完成
        int exitCode = process.waitFor();
        System.out.println("命令执行结束，退出码：" + exitCode);

    }

    public static void main(String[] args) throws IOException, InterruptedException {
        doGenerate("/Users/zqh/Documents/project/zqh-generator/zqh-generator-maker/generated/acm-template-pro-generator");

    }

}
